﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;

namespace EmailCollector
{
    public partial class listEmails : Form
    {
        XDocument doc;
        public listEmails()
        {
            InitializeComponent();
        }

        private void listEmails_Load(object sender, EventArgs e)
        {
            //Load XML document
            doc = XDocument.Load("DB.xml");

            //Get email amount and listing
            getEmails();
        }

        private void getEmails()
        {
            //Select all emails on email element
            var emails = from em in doc.Descendants("email")
                         select em;

            //Display total emails on db
            listboxEmail.Items.Add("Emails on DB: " + emails.Count().ToString());
            listboxEmail.Items.Add("");

            //Display emails on db
            foreach (var email in emails)
            {
                listboxEmail.Items.Add(email.Value);
            }
        }

        private void tbnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
